package db

import (
	"fmt"
	"strings"

	"git.sr.ht/~mil/mobroute/src/utilfuncs"
)

// LoadConnectionsVerbose loads the connections for the given connection IDs
func (c *DBConnection) LoadConnectionsVerbose(connIDs []string) (*[]ConnectionVerbose, error) {
	var (
		r     []ConnectionVerbose
		query = fmt.Sprintf(
			"select * from _vconndverbosewithextensions where conn_id in (%s) and source in (%s) order by from_stop_time",
			strings.Join(utilfuncs.ArrayWithValue(len(connIDs), "?"), ","),
			strings.Join(utilfuncs.ArrayWithValue(len(c.QuerySources), "?"), ","),
		)
		params = utilfuncs.Anyify(append(connIDs, utilfuncs.ArrayIntToArryString(c.QuerySources)...))
	)
	if err := queryToSlice(c, query, params, &r); err != nil {
		return nil, err
	} else {
		return &r, nil
	}
}
